﻿this.KHF=function(e) { 
  var h = document.getElementsByTagName('head');
  var stext = 
  "#keyboard_europeanlatin_help { text-align: left; padding: 0; background: #f5e3de; font-size: 8pt; font-family: Tahoma; cursor: default; padding: 4px; }"+
  "#keyboard_europeanlatin_help table { margin-top: 0; }"+
  "#keyboard_europeanlatin_help tr.out td { padding: 4px; border: solid 1px #ad4a28; font-size: 10pt; font-family: Cambria, Tahoma; font-weight: bold; text-align: center; background: white; }"+
  "#keyboard_europeanlatin_help th { padding: 2px 2px; font-size: 8pt; font-family: Tahoma; }"+
  "#keyboard_europeanlatin_help span.elkey { font-weight: normal; background: #e0e0e0; border: outset 1px; padding: 2px 6px; }"+
  "#keyboard_europeanlatin_help th.prompt { text-align: left; white-space: nowrap; }"+
  "#keyboard_europeanlatin_help tr.key th.prompt { background: white; border: none; font-weight: normal; text-align: right; }"+
  "#keyboard_europeanlatin_help tr.key th.title { background: white; border: none; font-weight: bold; vertical-align: middle; text-align: left; padding: 1px; }"+
  "#keyboard_europeanlatin_help tr.key th { min-width: 14px; margin: 2px; font-weight: normal; text-align: center; background: #e0e0e0; border: outset 1px; padding: 2px 2px; }"+
  "#keyboard_europeanlatin_help tr.out th.prompt { background: white; border: none; font-weight: normal; text-align: right; }"+
  "#keyboard_europeanlatin_help tr.gap th { background: white; border: none; height: 7px; }"+
  "#keyboard_europeanlatin_help p { font-weight: bold; }"+
  "#keyboard_eurolatin_tabsheets { color: black; border: solid 1px #ad4a28; margin: 0 4px 4px 4px; background: white; z-index: 101; }"+
  ".keyboard_eurolatin_tabsheet_selected { display: block; padding: 6px 6px 0 6px; }"+
  ".keyboard_eurolatin_tabsheet { display: none; }"+
  "#keyboard_eurolatin_tabs { margin: 4px 4px 0 4px; z-index: 100; }"+
  ".keyboard_eurolatin_tab { background: white; color: #ad4a28; border: solid 1px #ad4a28; display: inline; padding: 1px 4px 0px 4px; height: 16px; }"+
  ".keyboard_eurolatin_tab_selected { background: white; color: #ad4a28; border: solid 1px #ad4a28; display: inline; padding: 1px 4px; border-bottom: none; margin-top: -1px; height: 18px;}";

  var style = document.createElement("style");
  style.setAttribute("type", "text/css");
  if(style.styleSheet){// IE
   style.styleSheet.cssText = stext;
  } else {// w3c
  var cssText = document.createTextNode(stext);
  style.appendChild(cssText);
  }
  if(h && h.length > 0)
    h[0].appendChild(style);

  e=document.getElementById('keyboard_europeanlatin_help');
  if (typeof e.onselectstart!="undefined") //IE route
    e.onselectstart=function(){return false;};
  else
  {
    e.style.MozUserSelect="none";
    e.style.KhtmlUserSelect="none";
    e.style.UserSelect="none";
  }
  var ch = e.getElementsByTagName('td');      

  for(var i = 0; i < ch.length; i++)
  {               
    if(ch[i].attributes['o'])
    {                                                         
      var sxv = ch[i].attributes['x'].value, so = ch[i].attributes['o'].value, sc = ch[i].attributes['c'].value;
	  if(ch[i].attributes['p']) var sp = ch[i].attributes['p'].value; else var sp = '';
      // ch[i].title = 'The following combinations are available: '+so;
      var ce = function(tag){return document.createElement(tag);}
      var sx = '<table><tr class="key">', sy = '<tr class="out">', sz = (sp == '' ? '' : sy);
      var e2 = ce('div');
      for(var j = 0; j < sc.length; j++)
      {
		var chvo = so.charAt(j), chvc = sc.charAt(j), chvp = sp.charAt(j);
		/* Special case for characters p umlaut, g tilde because they aren't precomposed */
		if(sxv == ':' && chvo == 'p') { chvo = 'p̈'; chvp = 'P̈'; }
		if(sxv == '~' && chvo == 'g') { chvo = 'g̃'; chvp = 'G̃'; }
        sx += '<th>'+sxv+chvc+'</th>';
        sy += '<td>'+chvo+'</td>';
		if(sp != '') sz += '<td>'+chvp+'</td>';
      }
      e2.innerHTML = sx+'</tr>'+sy+'</tr>'+sz+(sz == '' ? '' : '</tr>')+'</table>';
      
      var es = e2.style;
      es.background = '#f3ffdf';
      es.border = 'solid 1px #ad4a28';
      es.padding = '2px';
      es.display = 'none';
      es.position = 'absolute';
      es.left = (ch[i].offsetLeft+4)+'px';
      es.top = '24px';
      e2.onclick = function() { KeymanWeb.KT(); window.event.cancelBubble=true; return false; }
      
      ch[i].kmw_subitems = e2;
      ch[i].appendChild(e2);
      ch[i].onmouseover = function() { this.style.background = KeymanWeb_KeyHoverColor; this.kmw_subitems.style.left=this.offsetLeft+4+'px'; this.kmw_subitems.style.top=(this.offsetParent.offsetTop+this.offsetTop+this.offsetHeight-2)+'px'; this.kmw_subitems.style.display = 'block'; return false; }
      ch[i].onmouseout = function() { this.style.background = ''; this.kmw_subitems.style.display = 'none'; return false; }
    }
    else
    {
      ch[i].onmouseover = function() { this.style.background = KeymanWeb_KeyHoverColor; return false; }
      ch[i].onmouseout = function() { this.style.background = ''; return false; }
    }
        
    ch[i].onclick = function(e) { with(this) { if(attributes['x']) KeymanWeb.KT(attributes['x'].value,0); else if(innerHTML != '&nbsp;') KeymanWeb.KT(innerHTML); else KeymanWeb.KT(''); } if(!e)e=window.event;if(e) e.cancelBubble=true; }
    ch[i].onmousedown = function(e) { KeymanWeb.KSF(); if(!e)e=window.event;if(e) e.cancelBubble=true; }
  }

  e.onclick=function() { KeymanWeb.KT(''); return false; }
  e.onmousedown=function() { KeymanWeb.KSF(); return false; }
  
  e = document.getElementById('keyboard_eurolatin_tabs');
  e2 = document.getElementById('keyboard_eurolatin_tabsheets');
  var ch = [document.getElementById('keyboard_eurolatin_letters_tab'), document.getElementById('keyboard_eurolatin_symbols_tab')];
  var ch2 = [document.getElementById('keyboard_eurolatin_letters_tabsheet'), document.getElementById('keyboard_eurolatin_symbols_tabsheet')];
  for(var i = 0; i < ch.length; i++) 
	  ch[i].onclick = (function(i) { return function(e) 
	  { 
	    for(var j = 0; j < ch.length; j++)
	    {
		  ch[j].className = "keyboard_eurolatin_tab" + (i == j ? "_selected" : "");
		  ch2[j].className = "keyboard_eurolatin_tabsheet" + (i == j ? "_selected" : "");
		}
      }
    })(i); 
}